#include <iostream>
#include <unistd.h>
#include "../logs/log.h"

int main()
{
    // Log::LogSink::ptr stdout_lsp = Log::SinkFactory::create<Log::StdoutLogSink>();
    // Log::LogSink::ptr file_lsp = Log::SinkFactory::create<Log::FileLogSink>("./logfile/test1.log");
    // Log::LogSink::ptr rollSize_lsp = Log::SinkFactory::create<Log::RollByFileSizeLogSink>("./logfile/rollsize-", 1024 * 1024);
    // Log::LogSink::ptr rollTime_lsp = Log::SinkFactory::create<Log::RollByFileTimeLogSink>("./logfile/rolltime-",Log::TimeGap::GAP_MINUTE);
    // std::vector<Log::LogSink::ptr> sinks = {stdout_lsp, file_lsp, rollSize_lsp, rollTime_lsp};
    // Log::Logger::ptr logger(new Log::SyncLogger("日志器1", Log::LogLevel::value::INFO, sinks, Log::Formatter::ptr(new Log::Formatter)));

    std::unique_ptr<Log::LoggerBuilder> builder(new Log::LocalLoggerBuilder());
    builder->buildLoggerType(Log::LoggerType::LOGGER_SYNC);
    builder->buildLoggerName("同步日志1");
    builder->buildLimitLevel(Log::LogLevel::value::INFO);
    builder->buildFormatter("[%d{%Y-%m-%d %H:%M:%S}][%t][%f: %l]:[%p][%c]%T%m%n");
    builder->buildSinks<Log::StdoutLogSink>();
    builder->buildSinks<Log::FileLogSink>("./logfile/test1.log");
    builder->buildSinks<Log::RollByFileSizeLogSink>("./logfile/rollsize-", 1024 * 1024);
    //builder->buildSinks<Log::RollByFileTimeLogSink>("./logfile/rolltime-", Log::TimeGap::GAP_MINUTE);
    Log::Logger::ptr logger = builder->build();

    std::string str = "用来测试同步日志器是否出错-";
    logger->debug(__FILE__, __LINE__, "%s", str.c_str());
    logger->info(__FILE__, __LINE__, "%s", str.c_str());
    logger->warnning(__FILE__, __LINE__, "%s", str.c_str());
    logger->error(__FILE__, __LINE__, "%s", str.c_str());
    logger->fatal(__FILE__, __LINE__, "%s", str.c_str());

    size_t cursize = 0;
    size_t count = 0;
    while(cursize < 1024*1024*10)
    {
        std::string tmp = str + std::to_string(count++);
        logger->fatal(__FILE__, __LINE__, "%s",tmp.c_str());
        cursize += tmp.size();
    }

    return 0;
}